package com.aliothservice.catfish.product.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.data.annotation.Id;

public class ProductService {
	
	public Map<String, Object> mapForSearchResult() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("keySpec", this.getKeySpec());
		map.put("name", this.getName());
		map.put("category", this.getCategory());
		map.put("province", this.getProvince());
		map.put("city", this.getCity());
		map.put("district", this.getDistrict());
		map.put("originProvince", this.getOriginProvince());
		map.put("originCity", this.getOriginCity());
		map.put("originDistrict", this.getOriginDistrict());
		map.put("productPhotoId", this.getProductPhotoId());
		map.put("title", this.getTitle());
		map.put("price", this.getPrice());
		map.put("stock", this.getStock());
		map.put("minimumVolume", this.getMinimumVolume());
		map.put("description", this.getDescription());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("availableStart", formatter.format(this.getAvailableStart()));
		map.put("availableUntil", formatter.format(this.getAvailableUntil()));
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("userHash", this.getUserHash());
		map.put("manInChargeName", this.getManInChargeName());
		if (this.getManInChargePhoneNumber().length() != 11) {
			map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		} else {
			String maskedPhoneNumber = String.format("%s*****%s", this.getManInChargePhoneNumber().substring(0, 2), this.getManInChargePhoneNumber().substring(7, 10));
			map.put("manInChargePhoneNumber", maskedPhoneNumber);
		}
		
		return map;
	}
	
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("keySpec", this.getKeySpec());
		map.put("name", this.getName());
		map.put("category", this.getCategory());
		map.put("province", this.getProvince());
		map.put("city", this.getCity());
		map.put("district", this.getDistrict());
		map.put("originProvince", this.getOriginProvince());
		map.put("originCity", this.getOriginCity());
		map.put("originDistrict", this.getOriginDistrict());
		map.put("productPhotoId", this.getProductPhotoId());
		map.put("title", this.getTitle());
		map.put("description", this.getDescription());
		map.put("price", this.getPrice());
		map.put("stock", this.getStock());
		map.put("minimumVolume", this.getMinimumVolume());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("availableStart", formatter.format(this.getAvailableStart()));
		map.put("availableUntil", formatter.format(this.getAvailableUntil()));
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("userHash", this.getUserHash());
		
		return map;
	}
	
	@Id
	private String id;

	// who owns this product
	private String userId;
	private String userHash;
	
	private String keySpec;
	
	private String name;
	private String category;
	private String province;
	private String city;
	private String district;
	private String originProvince;
	private String originCity;
	private String originDistrict;
	
	private String productPhotoId;
	
	private String title;
	private String description;
	private Integer minimumVolume;
	private Float price;
	private Integer stock;
	private Date availableStart;
	private Date availableUntil;
	
	private String individual;
	private String enterprise;
	
	private String manInChargeName;
	private String manInChargePhoneNumber;
	
	private LocalDateTime creationDate;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getKeySpec() {
		return keySpec;
	}

	public void setKeySpec(String keySpec) {
		this.keySpec = keySpec;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public String getOriginProvince() {
		return originProvince;
	}

	public void setOriginProvince(String originProvince) {
		this.originProvince = originProvince;
	}

	public String getOriginCity() {
		return originCity;
	}

	public void setOriginCity(String originCity) {
		this.originCity = originCity;
	}

	public String getOriginDistrict() {
		return originDistrict;
	}

	public void setOriginDistrict(String originDistrict) {
		this.originDistrict = originDistrict;
	}

	public String getProductPhotoId() {
		return productPhotoId;
	}

	public void setProductPhotoId(String productPhotoId) {
		this.productPhotoId = productPhotoId;
	}

	public Integer getStock() {
		return stock;
	}

	public void setStock(Integer stock) {
		this.stock = stock;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public Date getAvailableStart() {
		return availableStart;
	}

	public void setAvailableStart(Date availableStart) {
		this.availableStart = availableStart;
	}

	public Date getAvailableUntil() {
		return availableUntil;
	}

	public void setAvailableUntil(Date availableUntil) {
		this.availableUntil = availableUntil;
	}

	public String getIndividual() {
		return individual;
	}

	public void setIndividual(String individual) {
		this.individual = individual;
	}

	public String getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(String enterprise) {
		this.enterprise = enterprise;
	}

	public String getUserHash() {
		return userHash;
	}

	public void setUserHash(String userHash) {
		this.userHash = userHash;
	}

	public String getManInChargeName() {
		return manInChargeName;
	}

	public void setManInChargeName(String manInChargeName) {
		this.manInChargeName = manInChargeName;
	}

	public String getManInChargePhoneNumber() {
		return manInChargePhoneNumber;
	}

	public void setManInChargePhoneNumber(String manInChargePhoneNumber) {
		this.manInChargePhoneNumber = manInChargePhoneNumber;
	}

	public Integer getMinimumVolume() {
		return minimumVolume;
	}

	public void setMinimumVolume(Integer minimumVolume) {
		this.minimumVolume = minimumVolume;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

}
